package com.fy56.platform.goodsTracking.service.impl;

import com.dexcoder.dal.JdbcDao;
import com.dexcoder.dal.build.Criteria;
import com.fy56.platform.goodsTracking.model.Jrpt;
import com.fy56.platform.goodsTracking.service.JrptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Calendar;
import java.util.List;

/**
 * Created by XTK on 2016-11-23.
 */
@Repository
public class JrptServiceImpl implements JrptService {
    @Autowired
    JdbcDao jdbcDao_GoodsTracked;

    @Override
    public void save(Jrpt jrpt) {
        jdbcDao_GoodsTracked.updateForSql("if exists(select JRPT.id from JRPT where OrganizationCode ='"+jrpt.getOrganizationcode()+"' )"
                + " update JRPT set JRPTUser='"+jrpt.getJrptuser()+"',JRPTPass='"+jrpt.getJrptpass()+"' where JRPT.organizationcode='"+jrpt.getOrganizationcode()+"' "
                + " else insert into JRPT(organizationcode,JRPTUser,JRPTPass,LostTime)"
                + " values('"+jrpt.getOrganizationcode()+"','"+jrpt.getJrptuser()+"','"+jrpt.getJrptpass()+"',GETDATE())");
    }

    @Override
    public List<Jrpt> select() {
        Criteria criteria = Criteria.select(Jrpt.class).where("jrptuser", "<>", new Object[]{""}).desc("organizationcode");
        return jdbcDao_GoodsTracked.queryList(criteria);
    }
    @Override
    public List<Jrpt> selectList(String appid) {
        Criteria criteria = Criteria.select(Jrpt.class).where("jrptuser", "<>", new Object[]{""})
                .and("appid","<>", new Object[]{""})
                .desc("organizationcode");
        return jdbcDao_GoodsTracked.queryList(criteria);
    }
    @Override
    public List<Jrpt> wxIdselectList(String wxid) {
        Criteria criteria = Criteria.select(Jrpt.class).where("jrptuser", "<>", new Object[]{""})
                .and("wxid","<>", new Object[]{""})
                .desc("organizationcode");
        return jdbcDao_GoodsTracked.queryList(criteria);
    }
    @Override
    public void delete(String organizationcode) {
        jdbcDao_GoodsTracked.updateForSql("delete from JRPT where organizationcode='" + organizationcode + "'");
    }

    @Override
    public void update(Jrpt jrpt) {
        jdbcDao_GoodsTracked.updateForSql("update JRPT set message='" + jrpt.getMessage() + "' where id=" + jrpt.getId());
    }

    @Override
    public void updateLast(Jrpt jrpt) {
        jdbcDao_GoodsTracked.updateForSql("update JRPT set Losttime='" + jrpt.getLosttime() + "' where id=" + jrpt.getId());
    }
}
